package com.ww.word.ui.more;

import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

import com.ww.core.activity.MyActivity;
import com.ww.core.util.DeviceUtil;
import com.ww.core.util.StringUtils;
import com.ww.core.util.email.EmailUtils;
import com.ww.word.R;

public class FeedBackActivity extends MyActivity {
	private EditText email, content;
	private boolean b = true;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.core_feedback);
		setTitle(R.string.feedback_title);
		email = (EditText) findViewById(R.id.email);
		content = (EditText) findViewById(R.id.content);
		Button send = (Button) findViewById(R.id.send);
		send.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				if (DeviceUtil.checkNet(FeedBackActivity.this)) {
					if (StringUtils.isNotEmpty(content.getText().toString())) {
						if (StringUtils.isNotEmpty(email.getText().toString())) {
							if (email.getText().toString().contains("@")) {
								showProgressDialog(FeedBackActivity.this, getString(R.string.feedback_loading));
								new Thread(new Runnable() {
									@Override
									public void run() {
										EmailUtils e = new EmailUtils(FeedBackActivity.this, email.getText().toString());
										b = e.sendEmail(content.getText().toString());
										handler.sendEmptyMessage(1);
									}
								}).start();
							} else {
								showMessage(R.string.feedback_email_format);
							}
						} else {
							showMessage(R.string.feedback_email_format);
						}
					} else {
						showMessage(R.string.feedback_content_empty);
					}
				}
			}
		});
	}

	Handler handler = new Handler() {
		public void handleMessage(android.os.Message msg) {
			hideProgressDialog();
			if (b) {
				showMessage(R.string.feedback_success);
				finish();
			} else {
				showMessage(R.string.feedback_fail);
			}

		};
	};

}
